package com.hongyuan.sellfitness.ui.person.view_mode;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.base.ItemViewModel;
import com.hongyuan.sellfitness.ui.home.activity.StoreCardActivity;
import com.hongyuan.sellfitness.ui.home.activity.StorePriviteLessonActivity;
import com.hongyuan.sellfitness.ui.person.beans.MyCouponBeans;

public class MyCouponItemViewModel extends ItemViewModel<MyCouponViewModel> {

    public ObservableField<MyCouponBeans.ListBean> entity = new ObservableField<>();

    public MyCouponItemViewModel(@NonNull MyCouponViewModel viewModel, MyCouponBeans.ListBean bean) {
        super(viewModel);
        entity.set(bean);
    }


    //去使用
    public BindingCommand goUse = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            String osId = viewModel.userToken.getOs_id();
            String[] os_ids = entity.get().getCoupon_os_ids().split(",");

            if(os_ids.length > 0){
                for(int i = 0 ; i < os_ids.length ; i++){
                    if(os_ids[i].equals(viewModel.userToken.getOs_id())){
                        osId = os_ids[i];
                    }
                }
            }

            if("2".equals(entity.get().getCoupon_for())){
                Bundle bundle = new Bundle();
                bundle.putString("os_id",osId);
                viewModel.startActivity(StoreCardActivity.class,bundle);
            }else if("3".equals(entity.get().getCoupon_for())){
                Bundle bundle = new Bundle();
                bundle.putString("os_id",osId);
                viewModel.startActivity(StorePriviteLessonActivity.class,bundle);
            }

        }
    });


}
